package com.ssr.master.controller.sys;

import com.ssr.master.common.Base.PageBase;
import com.ssr.master.common.Base.PageBean;
import com.ssr.master.common.exception.RegisterException;
import com.ssr.master.common.utils.ResultUtil;
import com.ssr.master.common.utils.StringUtils;
import com.ssr.master.modules.entity.SysUser;
import com.ssr.master.modules.service.SysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author ZhangPeng
 * @Description //todo 用户Controler
 * @date
 * @updateBy
 * @other
 **/
@Controller
@RequestMapping("/user")
public class SysUserController {
    private static Logger logger = LoggerFactory.getLogger(SysUserController.class);

    @Autowired
    private SysUserService sysUserService;

    /**
     * @param
     * @return java.lang.String
     * @Description //todo 获取用户列表页面
     * @author ZhangPeng
     * @date 2020/7/20 15:47
     * @other
     **/
    @RequestMapping("index")
    public String SysUserIndex(SysUser sysUser, HttpServletRequest request) {

        return "/sys/sysUserIndex";
    }

    /**
     * @param sysUser
     * @param request
     * @return com.ssr.master.common.Base.PageBean<com.ssr.master.modules.entity.SysUser>
     * @Description //todo 加载用户列表数据
     * @author ZhangPeng
     * @date 2020/7/21 15:23
     * @other
     **/
    @RequestMapping("list")
    @ResponseBody
    public PageBase<SysUser> list(SysUser sysUser, HttpServletRequest request) {
        PageBean<SysUser> pageBean = new PageBean<SysUser>();
        try {
            pageBean = sysUserService.findListPage(sysUser);
        } catch (RegisterException r) {
            logger.error("");
        } catch (Exception exception) {
            pageBean.setTotalNum(0);
            String error = exception.toString();
            pageBean.setErrorMsg(StringUtils.subStringAppoint(":", error));
            logger.error(error);
        }
        return ResultUtil.tablePage(pageBean);
    }


    @RequestMapping("remove")
    @ResponseBody
    public String remove(String id) {
        return "";
    }
}
